package com.hui.security.sys.controller;

import com.hui.security.common.response.ResultMapper;
import com.hui.security.common.response.ResultVO;
import com.hui.security.sys.exception.ExceptionEnum;
import com.hui.security.sys.exception.HSecurityException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <b><code>ErrorController</code></b>
 * <p/>
 * Description:
 * <p/>
 * <b>Creation Time:</b> 2019/1/8 18:22.
 *
 * @author Hu weihui
 */
//@RestController
//@Api(value = "错误返回", tags = "错误返回")
@Slf4j
public class InfoReturnController implements ErrorController {
    @RequestMapping("/401")
    public void page401() {
        throw new HSecurityException("401");
    }

    @RequestMapping("/403")
    public void page403() {
        throw new HSecurityException(ExceptionEnum.SECURITY_ERROR_PERMISSION_NOT_ENOUGH);
    }

    @RequestMapping("/index")
    public ResultVO pageIndex() {
        return ResultMapper.ok("成功登录,请跳转到登录页面");
    }

    @RequestMapping("/error")
    public void errorHandler() {
        throw new HSecurityException(ExceptionEnum.SECURITY_ERROR_FORBID_ACCESS);
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
